package com.ruoyi.wx.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wx.domain.WxApp;
import com.ruoyi.wx.domain.WxMpApp;
import com.ruoyi.wx.mapper.WxMpAppMapper;
import com.ruoyi.wx.service.IWxAppService;
import com.ruoyi.wx.service.IWxMpAppService;

/**
 * 公众号应用Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-19
 */
@Service
public class WxMpAppServiceImpl extends ServiceImpl<WxMpAppMapper, WxMpApp> implements IWxMpAppService 
{
    @Autowired
    private WxMpAppMapper wxMpAppMapper;
    
    @Autowired
    private IWxAppService wxAppService;
    
    @Autowired
    private IWxMpAppService wxMpAppService;

    /**
     * 查询公众号应用
     * 
     * @param id 公众号应用主键
     * @return 公众号应用
     */
    @Override
    public WxMpApp selectWxMpAppById(String id)
    {
        return wxMpAppMapper.selectWxMpAppById(id);
    }

    /**
     * 查询公众号应用列表
     * 
     * @param wxMpApp 公众号应用
     * @return 公众号应用
     */
    @Override
    public List<WxMpApp> selectWxMpAppList(WxMpApp wxMpApp)
    {
        return wxMpAppMapper.selectWxMpAppList(wxMpApp);
    }

    /**
     * 新增公众号应用
     * 
     * @param wxMpApp 公众号应用
     * @return 结果
     */
    @Override
    public int insertWxMpApp(WxMpApp wxMpApp)
    {
        wxMpApp.setCreateTime(DateUtils.getNowDate());
        return wxMpAppMapper.insertWxMpApp(wxMpApp);
    }

    /**
     * 修改公众号应用
     * 
     * @param wxMpApp 公众号应用
     * @return 结果
     */
    @Override
    public int updateWxMpApp(WxMpApp wxMpApp)
    {
        wxMpApp.setUpdateTime(DateUtils.getNowDate());
        return wxMpAppMapper.updateWxMpApp(wxMpApp);
    }

    /**
     * 批量删除公众号应用
     * 
     * @param ids 需要删除的公众号应用主键
     * @return 结果
     */
    @Override
    public int deleteWxMpAppByIds(String[] ids)
    {
        return wxMpAppMapper.deleteWxMpAppByIds(ids);
    }

    /**
     * 删除公众号应用信息
     * 
     * @param id 公众号应用主键
     * @return 结果
     */
    @Override
    public int deleteWxMpAppById(String id)
    {
        return wxMpAppMapper.deleteWxMpAppById(id);
    }

	@Override
	public WxMpApp getWxMpAppByWxId(String wxId) {
		QueryWrapper<WxMpApp> qw = new QueryWrapper<>();
		WxMpApp entity = new WxMpApp();
		entity.setWxId(wxId);
		qw.setEntity(entity);
		return wxMpAppMapper.selectOne(qw);
	}

	@Override
	public List<String> getQrCode(String appId) {
		WxApp app = wxAppService.getByAppid(appId);
		WxMpApp mp = wxMpAppService.getWxMpAppByWxId(app.getWxId());
		List<String> data = new ArrayList<String>();
		data.add(mp.getQrCode());
		return data;
	}
}
